package com.onehouse.domain.checkIn.model.entity;

import com.onehouse.domain.checkIn.model.valobj.BillStatus;
import com.onehouse.domain.checkIn.model.valobj.RoomDeposit;
import com.onehouse.domain.checkIn.model.valobj.RoomPriceMap;
import com.onehouse.domain.checkIn.model.valobj.RoomRate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.time.LocalDate;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CheckInBill {

    private BigDecimal totalAmount;
    private RoomRate roomRate;
    private RoomDeposit roomDeposit;
    private BillStatus billStatus;

    public void caculate(LocalDate checkInDate, LocalDate checkOutDate, RoomPriceMap roomPriceMap) {
        BigDecimal total = BigDecimal.ZERO;
        LocalDate currentDate = checkInDate;
        
        while (!currentDate.isAfter(checkOutDate)) {
            BigDecimal dailyPrice = roomPriceMap.get(currentDate);
            if (dailyPrice != null) {
                total = total.add(dailyPrice);
            }
            currentDate = currentDate.plusDays(1);
        }
        
        this.roomRate.setAmount(total);
        this.totalAmount = total.add(this.roomDeposit.getAmount());
    }

}
